package com.gsm.service.impl;

import com.gsm.entity.CourseDetails;
import com.gsm.dao.CourseDetailsDao;
import com.gsm.service.CourseDetailsService;
import com.gsm.entity.Result;
import com.gsm.utils.IdUtils;
import com.gsm.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程细节(CourseDetails)表服务实现类
 */
@Service
public class CourseDetailsServiceImpl implements CourseDetailsService {
    @Autowired
    private CourseDetailsDao courseDetailsDao;
    @Autowired
    private IdUtils idUtils;
    
    
    @Override
    public Result insertCourseDetails(CourseDetails courseDetails) {
        long courseDetailsId = idUtils.nextId();
        courseDetails.setCourseDetailsId(courseDetailsId);
        courseDetailsDao.insertCourseDetails(courseDetails);
        Result result = new Result(true,StatusCode.OK);
        return result;
    }
    
    /**
     * 根据 主键 courseDetailsId 删除
     * @param courseDetailsId 主键
     * @return
     */
    @Override
    public Result deleteCourseDetailsByCourseDetailsId(Long courseDetailsId) {
        courseDetailsDao.deleteCourseDetailsByCourseDetailsId(courseDetailsId);
        Result result = new Result(true, StatusCode.OK);
        return result;
    }
    
    /**
     * 修改
     * @param courseDetails 实例对象
     * @return
     */
    @Override
    public Result updateCourseDetailsByCourseDetailsId(CourseDetails courseDetails) {
        courseDetailsDao.updateCourseDetailsByCourseDetailsId(courseDetails);
        Result result = new Result(true, StatusCode.OK);
        return result;
    }
    
    /**
     * 根据 id 查询单条数据
     * @param courseDetailsId 主键
     * @return
     */
    @Override
    public Result selectCourseDetailsByCourseDetailsId(Long courseDetailsId) {
        CourseDetails courseDetails = courseDetailsDao.selectCourseDetailsByCourseDetailsId(courseDetailsId);
        Result result = new Result(true, StatusCode.OK,"",courseDetails);
        return result;
    }

    /**
     * 根据条件查询列表
     * @param courseDetails 实例对象
     * @return
     */
    @Override
    public Result selectCourseDetailsList(CourseDetails courseDetails) {
        List<CourseDetails> list = courseDetailsDao.selectCourseDetailsList(courseDetails);
        Result result = new Result(true, StatusCode.OK,"",list);
        return result;
    }
}